/**
* \brief 
* \author pengcheng (pengcheng@yslrpch@126.com)
* \date 2020-06-09
* \attention CopyrightÃ‚Â©ADC Technology(tianjin)Co.Ltd
* \attention Refer to COPYRIGHT.txt for complete terms of copyright notice
*/
#ifndef CMW_APP_DETECTION_CENTERNET_H__
#define CMW_APP_DETECTION_CENTERNET_H__
#include <cmw_app/work.h>
#include "detection_vision/center_net_detector.h"
#include "detection_vision/impl/bbox2d.hpp"
#include <opencv2/core/core.hpp>
#include <queue>
#include <chrono>
#include <memory>
#include <mutex>

namespace adc
{

class DetectionCenternet : public Worker
{
public:
    using Ptr = std::shared_ptr<DetectionCenternet>;
    using ConstPtr = std::shared_ptr<const DetectionCenternet>;

    typedef detection::ImageBBox2D<float> ImageBBox2DType;
    typedef std::chrono::system_clock::time_point  TimeType;
    typedef std::function<void(std::vector<ImageBBox2DType>&, TimeType&)> DetectionCallback;
    typedef std::function<void(std::vector<ImageBBox2DType>&, cv::Mat&, TimeType&)> DetectionImgCallback;
    DetectionCenternet(const std::string& config_file, const float hz);

    void DoWork();
    void CacheImages(const cv::Mat& img, TimeType& tm);
    bool ReceiveImage(void);
    void SetDetectionCallback(DetectionCallback callback);
    void SetDetectionImgCallback(DetectionImgCallback callback);

private:
    void InitConfig(const std::string& config_file);
private:
    std::mutex mutex_image_;
private:   
    std::queue<cv::Mat> image_cache_;
    std::queue<std::chrono::system_clock::time_point> time_cache_;

    detection::CenterNetDetector<float>::Ptr center_net_ptr_;
    cv::Mat current_img_;
    std::chrono::system_clock::time_point  current_time_;

    std::vector<std::vector<ImageBBox2DType>> res_bbox_;

    const size_t kQueueSize = 10;
    DetectionCallback detection_callback_;
    DetectionImgCallback detection_img_callback_;
};

}

#endif 

